import axios from 'axios'

const request = axios.create({
	timeout: '5000'
})


request.interceptors.request.use((config) => {
	config.headers.common['Authorization'] = 'token'
	return config
}, (error) => {
	return Promise.reject(error)
})

request.interceptors.response.use((response) => {
	const { code } = response.data
	if(code === 500 ) {
		console.log('服务器问题');
	}

	if(code === 401 ) {
		console.log('权限问题');
	}
	return response
}, (error) => {
	if(error.response && error.response.status !== 200) {
		console.log('接口有问题');
	}
	return Promise.reject(error)
})

export default request